<template>
  <el-col :span="24" class="colmargin">
    <el-col :span="8" >
    <el-radio-group
      v-model="indextab"
      @change="getExecutionList"
      style="margin-bottom: 10px"
    >
     
      <el-radio-button size="small" label="2">耗材</el-radio-button>
      <el-radio-button size="small" label="3">项目</el-radio-button>
    </el-radio-group>
    </el-col >
    <el-col :span="8" >
     <el-input v-model="keyvalue2" placeholder="输入搜索内容" @input="souinput" size="small"></el-input>
        </el-col >
          <el-col :span="8" >
        </el-col >

  <div v-if="indextab=='2'">
     <el-table
                  :data="tableData"
                  style="width: 100%"
                  border
                  height="500"
                
                >
                  <template v-for="(item, index) in tabList">
                    <el-table-column
                      :width="item.width"
                      :prop="item.prop"
                      :fixed="item.left"
                      :label="item.name"
                      :key="index"
                    >
                    </el-table-column>
                  </template>
                                <el-table-column
                      label="操作"
                       fixed="right"
                    >
                      <template slot-scope="scope">
                  <el-button
                    @click.native.prevent="addserve(scope.row.id,2)"
                   
              
                  >
                    添 加
                  </el-button>
                </template>
                    </el-table-column>
                </el-table>
  </div>
  <div v-if="indextab=='3'">
     <el-table
                  :data="tableData3"
                  style="width: 100%"
                  border
                  height="500"
                
                >
                  <template v-for="(item, index) in serveTitle">
                    <el-table-column
                      :width="item.width"
                      :prop="item.prop"
                      :fixed="item.left"
                      :label="item.name"
                      :key="index"
                    >
                    </el-table-column>
                  </template>
                     <el-table-column
                      label="操作"
                      fixed="right"
                    >
                      <template slot-scope="scope">
                  <el-button
                    @click.native.prevent="addserve(scope.row.id,1)"
                   
                  
                  >
                    添 加
                  </el-button>
                </template>
                    </el-table-column>
                </el-table>
  </div>
             <el-pagination
            background
            @size-change="handleSizeChange"
            :current-page="page"
            :page-sizes="[10, 20, 30, 100]"
            :page-size="limit"
            layout="sizes , total , prev, pager, next , jumper"
            @current-change="handlePagination"
            :total="userCount">
            </el-pagination>
  
  </el-col>
  
</template>

<script>

import {  

  drugDrugIndex,

  service_feeServiceIndex,
  getCate1305,
  getCate1306,
  getCate1301,
getDrugItem,
project_save
  } from "@/api/dataDictionaries"
export default {
  // name:"costsRecord",
  props: ["id"],
  data() {
    return {
      tableData: [],
      tableData2: [],
      tableData3: [],
      patientlist:[],
      indextab: "2",
      money: "",
      centerDialogVisible: false,
      item: {},
      tableTitle1: [
        {
          prop: "name",
          label: "名称",
        },
        {
          prop: "created_at",
          label: "时间",
        },
        {
          prop: "price",
          label: "金额",
        },
      ],
      tabList : [{
        prop: "check",
        name: "目录对照",
        type: 12,
        width: 80
    },
    {
        prop: "index",
        name: "序号",
        type: 1,
        width: 80
    },
    {
        prop: "number",
        name: "药品编码",
        type: 1,
        width: 100
    },
    {
        prop: "yb_code",
        name: "国家药品编码",
        type: 1,
        width: 250,
    },
    {
        prop: "yb_name",
        name: "国家药品名称",
        type: 1,
        width: 220,
    },
    {
        prop: "name",
        name: "药品名称",
        type: 1,
        width: 200
    },
    {
        prop: "price",
        name: "价格",
        type: 1,
    },
    {
        prop: "drugstdcode",
        name: "本位码",
        type: 1,
        width: 200
    },
    {
        prop: "drug_code",
        name: "批准文号",
        type: 1,
        width: 200
    },

    {
        prop: "specification",
        name: "规格",
        type: 1,
        width: 150
    },
    {
        prop: "pack_specification",
        name: "包装单位",
        type: 1,
        width: 80
    },
    {
        prop: "dose_unit",
        name: "制剂单位",
        type: 1,
        width: 200
    },
    {
        prop: "form_of_drug",
        name: "剂型",
        type: 1,
        width: 200
    },
    {
        prop: "origin_factory",
        name: "生产企业",
        type: 1,
        width: 300
    },
    {
        prop: "is_up",
        name: "是否上传",
        type: 1,
    },
    // {
    //   prop:"updated_at",
    //   name:"更新时间",
    //   type:1,
    // },
    {
        prop: "status",
        name: "状态",
        type: 5,
        width: 80
    },
    {
        prop: "",
        name: "操作",
        type: 4,
        width: 200,
        arr: [
        ],

    },
],
serveTitle :[{
        prop: "number",
        name: "编码",
        type: 1,
        width: 80
    },
    {
        prop: "categoryName",
        name: "费用种类",
        type: 1,
        width: 80
    },
    {
        prop: "name",
        name: "名称",
        type: 1,
    },
    {
        prop: "unit",
        name: "单位",
        type: 1,
    },
    {
        prop: "price",
        name: "价格",
        type: 1,
    },
    {
        prop: "yb_code",
        name: "国家项目代码",
        type: 1,
    },
    {
        prop: "yb_name",
        name: "国家项目代码",
        type: 1,
    },
    {
        prop: "local_code",
        name: "地方项目代码",
        type: 1,
    },
    {
        prop: "min_prepunt",
        name: "状态",
        type: 5,
    },
   
],
tabData:[],
userCount:0,
keyValueSelect:'',
keyvalue:'',
keyvalue2:'',
page:1,
limit:13,
page2:1,
limit2:20,
userCount2:0
    };
  },
  mounted() {
  this.drugDrugIndex()
  },
    watch:{
      
   },
  methods: {
    getExecutionList(){
          if(this.indextab=='1'||this.indextab=='2'){
            this.tableData=[]
            this.drugDrugIndex()
          }else{
            this.service_feeServiceIndex()
          }
          this.patientlist=[]
          this.page2=1
          this.limit2=20
    },
    souinput(){
        if(this.indextab=='1'||this.indextab=='2'){
            this.tableData=[]
            this.drugDrugIndex()
          }else{
            this.service_feeServiceIndex()
          }
    },
       drugDrugIndex(){
         if(this.indextab=='2'){
          
            this.species_id=3
         }else{
           this.species_id=''
         }
       drugDrugIndex({keyword:this.keyvalue2,status:this.keyValueSelect,page:this.page,limit:this.limit,species_id:this.species_id})
       .then(res=>{
         
           res.data.list.map((item,index)=>{
              item.flag = item.status == 1 ? true : false;
              item.index = index+1;
              item.is_up=item.is_up==1?'已上传':'未上传'
              return item
            })
          console.log("ddLLL::::",res.data.list);
            this.userCount = res.data.count
            this.tableData =res.data.list
       })
       .catch(e=>{
          this.$message({
            message:e.message,
            type: 'error'
          });
       })
    },
        service_feeServiceIndex(){
       service_feeServiceIndex({keyword:this.keyvalue2,status:this.keyValueSelect,page:this.page,limit:this.limit,category_id:this.category_id})
       .then(res=>{
         this.userCount = res.data.count
         if(res.data.list.length == 0){
           return false
         }
         res.data.list.map((item)=>{
           item.flag = item.status == 1 ? true : false
           if(item.execute_dept){
             item.make_dept = item.execute_dept.id
           }
           if(item.category){
              item.categoryName = item.category.name
           }
          item.is_up=item.is_up==1?'已上传':'未上传'
           return item
         })
         console.log(this.userCount)
         this.tableData3 = res.data.list
      
       })
       .catch(e=>{
          this.$message({
            message:e.message,
            type: 'error'
          });
       })
     },
     addserve(id,type){
          project_save({business_id:id,type:type}).then(res=>{
                  if(res.code==200){
                     this.$message({
            message:"添加成功",
            type: 'success'
          });
                  }else{
                      this.$message({
            message:res.message,
          
          });
                  }
          })
     },
       handleSizeChange2(e){
       this.limit2 = e
this.getCate()

       
     },
          handleSizeChange(e){
       this.limit = e
     
          this.tableData = []
          this.tableData3 = []
             if(this.indextab=='1'||this.indextab=='2'){
            this.drugDrugIndex()
          }else{
            this.service_feeServiceIndex()
          }
       
     },
            handlePagination2(e){
       this.page2 = e
     
         this.getCate()
     },
          handlePagination(e){
       console.log(e)
       this.page = e
       this.tableData = []
          this.tableData3 = []
             if(this.indextab=='1'||this.indextab=='2'){
            this.drugDrugIndex()
          }else{
            this.service_feeServiceIndex()
          }
       },
       rowClick1(row){

  this.keyvalue=row.name
  this.page2=1
          this.limit2=20
 this.getCate()
         
       },
       getCate(){
            if(this.indextab=='1'){
               getCate1301({keyword:this.keyvalue,page:this.page2, limit:this.limit2}).then(res=>{
        console.log(res)
          this.patientlist=res.data.lists
        this.userCount2=res.data.total
  })
            }else if(this.indextab=='2'){
getCate1306({keyword:this.keyvalue,page:this.page2, limit:this.limit2}).then(res=>{
        console.log(res)
        this.patientlist=res.data.lists
        this.userCount2=res.data.total
  })
            }else {
 getCate1305({keyword:this.keyvalue,page:this.page2, limit:this.limit2}).then(res=>{
        console.log(res)
           this.patientlist=res.data.lists
        this.userCount2=res.data.total
  })
            }
       },
           rowClick2(row){
  this.keyvalue=row.name
  this.page2=1
          this.limit2=20
  this.getCate()
         
       },
           rowClick3(row){
 this.keyvalue=row.name
  this.page2=1
          this.limit2=20
 this.getCate()
         
       }
  },
};
</script>

<style scoped>
.colmargin {
  overflow: auto;
}
.see_box .el-col {
  margin: 5px 0px;
  font-size: 20px;
}
.see_box .span {
  color: dimgray;
  font-size: 18px;
  text-indent: 2em;
}
.span {
  color: dimgray;
  font-size: 13px;
  text-indent: 2em;
}
.colmargin .el-col {
  margin: 2px 0px;
}
</style>